-
Notifications
You must be signed in to change notification settings - Fork 423
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Explicit conversion to string in htmlspecialchars #387
Conversation
Solving PHP 8.1 deprecation warning: htmlspecialchars(): Passing null to parameter bobthecow#1 ($string) of type string is deprecated
Should fix #383 |
@bobthecow could you please give me a feedback to this PR? |
Thanks for the pull request! I haven't thought through all the implications of this change, but I'm not sure it's the best answer. See my comment here: #386 (comment) |
@bobthecow I see. It would convert error to warning this way, if wrong variable is provided. |
Integers should be casted automatically thanks to PHP being permissive. Other variables should generate an error.
Does it look better now? |
It … might surprise you to learn the minimum supported PHP version for this library 😛 Thinking through this a bit more, here's what basically anything you can render looks like:
We need to maintain the current (un-cast) behavior. It makes sense for a template engine. It turns out that, with or without an explicit cast, everything behaves correctly for all scalars all the way up to PHP 8.0. PHP 8.1 looks just like PHP 8.0, but they throw in this deprecation warning when calling For everything that's not a scalar, we don't want an explicit cast. Casting non-scalars to strings gives us the literal string Which leaves us with one outlier: Thank you so much for working on this. I'll push the fix I have in mind, and get it in the next release. |
Yes, good point about the older versions :D |
Solving PHP 8.1 deprecation warning: htmlspecialchars(): Passing null to parameter #1 ($string) of type string is deprecated